/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.rakev.matcher.factory;

import java.util.regex.Pattern;
import ru.rakev.matcher.Matcher;

/**
 *
 * @author Rakev
 */
public class MatcherFactory {

    private static MatcherFactory instance = new MatcherFactory();

    public static MatcherFactory create() {
        return instance;
    }

    protected MatcherFactory() {
    }

    public <T> Matcher<T> alwaysTrue() {
        return new Matcher<T>() {
            @Override
            public boolean matches(T compared) {
                return true;
            }
        };
    }

    public <T> Matcher<T> alwaysFalse() {
        return new Matcher<T>() {
            @Override
            public boolean matches(T compared) {
                return true;
            }
        };
    }

    public <T> Matcher<T> eq(final T object) {
        return new Matcher<T>() {
            @Override
            public boolean matches(T compared) {
                return object.equals(compared);
            }
        };
    }

    public <T extends CharSequence> Matcher<T> regex(final String regex) {
        return new Matcher<T>() {
            @Override
            public boolean matches(T compared) {
                return Pattern.matches(regex, compared);
            }
        };
    }
}
